﻿using System;
using System.Text;
using jQueryCSharp.Extensions;

namespace jQueryCSharp.ui
{
    public class Button : jQueryCSharpBase
    {
        #region Constantes
        private const bool DISABLED = false;
        private const bool TEXT = true;
        private const bool ISLINK = false;
        private const string ICONPRIMARY = "";
        private const string ICONSECUNDARY = "";
        private const string LABEL = "";
        private const string CLICK = "";


        #endregion

        /// <summary>
        /// Construtor
        /// </summary>
        public Button( )
            : this( "" )
        {

        }

        /// <summary>
        /// Construtor
        /// </summary>
        public Button( string identifier )
        {
            Disabled = DISABLED;
            Text = TEXT;
            IconPrimary = ICONPRIMARY;
            IconSecundary = ICONSECUNDARY;
            Label = LABEL;
            Click = CLICK;
            IsLink = ISLINK;

            if ( !String.IsNullOrEmpty( identifier ) )
            {
                if ( identifier.Contains( "#" ) )
                {
                    ID = identifier.Replace( "#", "" );
                }
                else
                {
                    Class = identifier.Replace( ".", "" );
                }
            }
        }

        #region Propriedades
        public bool Disabled { get; set; }
        public bool Text { get; set; }
        public bool IsLink { get; set; }
        public string IconPrimary { get; set; }
        public string IconSecundary { get; set; }
        public string Label { get; set; }
        public string Click { get; set; }
        #endregion

        #region Override

        public override string ToString( )
        {
            var sb = new StringBuilder( );

            if ( Disabled != DISABLED )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "disabled", Disabled.ToString( ).ToLower( ) ) );
            }

            if ( Text != TEXT )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "text", Text.ToString( ).ToLower( ) ) );
            }

            //Icons
            if ( IconPrimary != ICONPRIMARY || IconSecundary != ICONSECUNDARY )
            {
                var tmp = new StringBuilder( );
                if ( sb.Length > 0 ) sb.Append( "," );

                if ( IconPrimary != ICONPRIMARY )
                {
                    tmp.Append( "primary: '" );
                    tmp.Append( IconPrimary );
                    tmp.Append( "'" );
                }
                if ( tmp.Length > 0 ) tmp.Append( ", " );

                if ( IconSecundary != ICONSECUNDARY )
                {
                    tmp.Append( "secundary: '" );
                    tmp.Append( IconSecundary );
                    tmp.Append( "'" );
                }

                sb.Append( modelo.Formatar( "icons", "{{{0}}}".Formatar( tmp.ToString( ) ) ) );
            }

            if ( Label != LABEL )
            {
                if ( sb.Length > 0 ) sb.Append( "," );
                sb.Append( modelo.Formatar( "Label", "'{0}'".Formatar( Label ) ) );
            }


            if ( sb.Length > 0 )
            {
                return String.Concat( "{", sb.ToString( ), "}" );
            }

            return sb.ToString( );
        }

        #endregion
    }
}
